//
//  NetWorker.m
//  掌上宏力
//
//  Created by admin on 2017/5/22.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "NetWorker.h"

@implementation NetWorker

singleton_implementation(NetWorker)

//宏信通密码
-(void)setHxtPWD:(NSString *)hxtPWD{
    [[NSUserDefaults standardUserDefaults] setValue:hxtPWD forKey:@"hxtpwd"];
}
-(NSString *)hxtPWD{
    return [[NSUserDefaults standardUserDefaults] valueForKey:@"hxtpwd"];
}

//登录
-(void)setIsLogin:(BOOL)isLogin{
    NSString *statue = @"";
    if (isLogin) {
        statue = @"YES";
    }else{
        statue = @"NO";
    }
    [[NSUserDefaults standardUserDefaults] setValue:statue forKey:@"loginStatue"];
}

-(BOOL)isLogin{
    NSString *statue = [[NSUserDefaults standardUserDefaults] valueForKey:@"loginStatue"];
    return [statue isEqualToString:@"YES"];
}

//指纹登录
-(void)setIsTouchId:(BOOL)isTouchId{
    NSString *statue = @"";
    if (isTouchId) {
        statue = @"YES";
    }else{
        statue = @"NO";
    }
    [[NSUserDefaults standardUserDefaults] setValue:statue forKey:@"touchIdState"];
}

-(BOOL)isTouchId{
    NSString *statue = [[NSUserDefaults standardUserDefaults] valueForKey:@"touchIdState"];
    return [statue isEqualToString:@"YES"];
}

//登录时间
-(void)setLoginTime{
    long long seconds = [[NSDate date] timeIntervalSince1970];
    NSString *secondsFrom1970 = [NSString stringWithFormat:@"%lli",seconds];
    [[NSUserDefaults standardUserDefaults] setValue:secondsFrom1970 forKey:@"loginTimeKey"];
}

//计算登录时长
-(BOOL)updateExpriedStatue{
    NSString *lastLoginTime = [[NSUserDefaults standardUserDefaults] valueForKey:@"loginTimeKey"];
    long long lastLoginSeconds1970 = [lastLoginTime longLongValue];
    long long nowSeconds1970 = [[NSDate date] timeIntervalSince1970];
    long long diffValue = nowSeconds1970 - lastLoginSeconds1970;
    //判断是否超过规定的过期时间 7天
    BOOL expried = diffValue >= 3600*24*7 ? YES : NO;
    
    return expried;
}

@end
